/*
    会员管理:审核管理
 */
$(function () {
    let userId = getQueryString("userId");
    let url = '../audit/list';
    if (userId) {
        url += '?userId=' + userId;
    }
    $("#jqGrid").Grid({
        url: url,
        colModel: [
            {label: 'id', name: 'id', index: 'id', key: true, hidden: true},
            {label: '用户编号', name: 'userId', index: 'userId', width: 20},
            // {label: 'sessionId', name: 'sessionId', index: 'session_id', width: 80 },
            {label: '真实姓名', name: 'name', index: 'name', width: 30},
            {label: '证件类型', name: 'type', index: 'type', width: 20},
            // {label: '产品Id', name: 'productId', index: 'product_id', width: 80 },
            {label: '证件号', name: 'idCardNo', index: 'idCardNo', width: 30},
            {
                label: '正面图', name: 'frontImg', index: 'frontImg', width: 60, formatter: function (value) {
                    return transImg(value);
                }
            },
            {
                label: '反面图', name: 'reverseImg', index: 'reverseImg', width: 60, formatter: function (value) {
                    return transImg(value);
                }
            },
            {
                label: '审核状态', name: 'statu', index: 'statu', width: 20, formatter: function (value) {
                    if (value == 1) {
                        return '<span class="label label-info">待审核</span>';
                    }else if (value == 2) {
                        return '<span class="label label-success">审核通过</span>';
                    } else {
                        return '<span class="label label-danger">审核拒绝</span>';
                    }

                }
            },
            {
                label: '创建日期', name: 'createDate', index: 'createDate', width: 60, formatter: function (value) {
                    return transDate(value, "yyyy-MM-dd hh:mm:ss")
                }
            }
            // {label: 'product表对应的goods_specifition_ids', name: 'goodsSpecifitionIds', index: 'goods_specifition_ids', width: 80 },
            // {label: '', name: 'checked', index: 'checked', width: 80 },
            // {label: '商品图片', name: 'listPicUrl', index: 'list_pic_url', width: 80 }
        ]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        audit: {},
        ruleValidate: {
            name: [
                {required: true, message: '名称不能为空', trigger: 'blur'}
            ]
        },
        q: {
            name: '',
            uid: ''
        }
    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";
            vm.audit = {};
        },
        update: function (event) {
            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            vm.showList = false;
            vm.title = "修改";

            vm.getInfo(id)
        },
        saveOrUpdate: function (event) {
            var url = vm.audit.id == null ? "../audit/save" : "../audit/update";
            Ajax.request({
                type: "POST",
                url: url,
                contentType: "application/json",
                params: JSON.stringify(vm.audit),
                successCallback: function (r) {
                    alert('操作成功', function (index) {
                        vm.reload();
                    });
                }
            });
        },
        del: function (event) {
            var ids = getSelectedRows("#jqGrid");
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                Ajax.request({
                    type: "POST",
                    url: "../audit/delete",
                    contentType: "application/json",
                    params: JSON.stringify(ids),
                    successCallback: function (r) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        pass: function (event) {

            var id = getSelectedRow("#jqGrid");
            if (id == null) {
                return;
            }
            confirm('确定要通过选中的记录？', function () {
                Ajax.request({
                    type: "GET",
                    url: "../audit/pass/"+ id,
                    contentType: "application/json",
                    // params: JSON.stringify(ids),
                    successCallback: function (r) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        reject: function (event) {
            var id = getSelectedRows("#jqGrid");
            if (id == null) {
                return;
            }
            confirm('确定要拒绝选中的记录？', function () {
                Ajax.request({
                    type: "GET",
                    url: "../audit/reject/"+ id,
                    contentType: "application/json",
                    successCallback: function (r) {
                        alert('操作成功', function (index) {
                            vm.reload();
                        });
                    }
                });
            });
        },
        getInfo: function (id) {
            Ajax.request({
                url: "../audit/info/" + id,
                async: true,
                successCallback: function (r) {
                    vm.audit = r.audit;
                }
            });
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleSuccessFront: function (res, file) {
            vm.audit.frontImg = file.response.url;
        },
        handleSuccessReverse: function (res, file) {
            vm.audit.reverseImg = file.response.url;
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },
        handleFormatError: function (file) {
            this.$Notice.warning({
                title: '文件格式不正确',
                desc: '文件 ' + file.name + ' 格式不正确，请上传 jpg 或 png 格式的图片。'
            });
        },
        handleMaxSize: function (file) {
            this.$Notice.warning({
                title: '超出文件大小限制',
                desc: '文件 ' + file.name + ' 太大，不能超过 2M。'
            });
        },
        eyeImageFront: function () {
            var url = vm.audit.frontImg;
            eyeImage(url);
        },
        eyeImageReverse: function () {
            var url = vm.audit.reverseImg;
            eyeImage(url);
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'name': vm.q.name,'uid': vm.q.uid},
                page: page
            }).trigger("reloadGrid");
        },
        reloadSearch: function() {
            vm.q = {
                name: '',
                uid: ''
            }
            vm.reload();
        }
    }
});